package hanjia;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/10-下午12:51
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode59 {

    public int[][] generateMatrix(int n) {


        int startX=0;
        int startY=0;
        int[][] result = new int[n][n];
        int count=1;
        int round=n/2;
        int i=0;
        int j=0;
        int offset=1;
        while (round>0){
            for (j=startY;j<n-offset;j++){
                result[startX][j]=count;
                count++;
            }
            for (i=startX;i<n-offset;i++){
                result[i][j]=count;
                count++;
            }
            for (;j>startY;j--){
                result[i][j]=count;
                count++;
            }
            for (;i>startX;i--){
                result[i][j]=count;
                count++;
            }
            round--;
            startX++;
            startY++;
            offset++;
        }
        if (n%2==1){
            result[n/2][n/2]=count;
        }
        return result;



    }
}
